using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Threading;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Net;

namespace NetMonitor.Things
{
    public class PingThing : Thing
    {

        protected override int ping()
        {            
            
            Ping ping = new Ping();
            
            PingReply reply = ping.Send(hostname, timeOut);
            if (reply.Status != IPStatus.Success)
                return -1000 - (int)reply.Status;
            return (int)reply.RoundtripTime;
        }

        public override void drawThing(Graphics g)
        {
            Pen pen = new Pen(col);
            float o, penWidth = 14;

            o = (float)penWidth / 2.0f;

            SizeF stringSize = new SizeF();
            string s = getText();
            if (history.Count > 0)
                s += " (" + history[history.Count - 1].ToString() + ")";
            stringSize = g.MeasureString(s, font);
            boxW = stringSize.Width;
            boxH = stringSize.Height;
            boxX = w / 2 + x - boxW / 2;
            boxY = h / 2 + y - boxH / 2;

            pen.EndCap = LineCap.Triangle;
            pen.StartCap = LineCap.Triangle;
            pen.Color = Color.FromArgb(255, col);
            pen.Width = 14;

            g.DrawLine(pen, x, y, x + w, y + h);

            
            g.FillRectangle(new SolidBrush(Color.White), boxX, boxY, boxW, boxH);
            g.DrawRectangle(new Pen(boxColor,3), boxX, boxY, boxW, boxH);
            
            g.DrawString(s , font, new SolidBrush(col), new PointF(boxX, boxY));
        }
    }
}
